import React from 'react'
import { Form, Select, Modal } from 'antd'
const FastModal = ({
  visible,
  dispatch,
  currentItem,
  commodityStoreList,
  currentOption,
}) => {
  const Option = Select.Option

  const buildOption = () => {
    if (_.isArray(commodityStoreList)) {
      return commodityStoreList.map((element) => {
        return <Option key={element.id} title={element.name}>
          {element.name}
        </Option>
      })
    }
  }
  const setCurrentOption = (value) => {
    dispatch({
      type: 'salesDistributorRegistryApply/setCurrentOption',
      payload: value
    })
  }

  return (
    <div>
      <Modal
        visible={visible}
        title={"快速分配售卖商品"}
        loading={global}
        width={355}
        destroyOnClose={true}
        onOk={() => {
          dispatch({
            type: 'storelist/assignStore',
            payload: {
              distributorId: currentItem.distributorId,
              commodityStoreId: currentOption
            }
          })
          dispatch({
            type: 'salesDistributorRegistryApply/setFastVisible',
            payload: false
          })
        }
        }
        onCancel={() => dispatch({
          type: 'salesDistributorRegistryApply/setFastVisible',
          payload: false
        }

        )}>
        <Select style={{ width: 300 }} placeholder="请选择商品库" onSelect={(value) => setCurrentOption(value)} filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} showSearch>
          {buildOption()}
        </Select>
      </Modal>


    </div>
  )
};
export default Form.create()(FastModal)
